<?php
namespace app\common\service\impl;
use app\common\enums\ResultEnum;
use app\common\model\Agency;
use app\common\model\Brand;
use app\common\model\User;
use app\common\service\CommonService;
use app\common\exception\ZeduException;
class CommonServiceImpl implements CommonService
{
    
    public function findUser(array $param)
    {
        if(!empty($param['name'])){
            $data = User::where($param)->value('id');
            if($data){
                return $data;
            }else{
                throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>$param['name'].'该用户不存在']);
            }
            
        }else{
            throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>'客户名称不能为空']);
        }
       
    }
    
    public function findAgency(array $param)
   {
       if(!empty($param['name'])){
           $data = Agency::where($param)->value('id');
           
           if($data){
               return $data;
           }else{
               throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>$param['name'].'不存在']);
           }
           
       }else{
           throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>'加盟商不能为空']);
       }
        
        
    }
    
    public function findBrand(array $param)
    {
        if(!empty($param['name'])){
            $data = Brand::where($param)->value('id');
            
            if($data){
                return $data;
            }else{
                throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>$param['name'].'不存在']);
            }
            
        }else{
            throw new ZeduException(['code'=>ResultEnum::FIND_ERROR['code'],'msg'=>'车型不能为空']);
        }   
    }
    
}

